package com.example.mvc.controller;

import com.example.mvc.service.BrandService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/deleteByIdServlet")
public class DeleteByIdServlet extends HttpServlet {
    private BrandService brandService = new BrandService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, IOException {
        //1. 接收id
        String id = request.getParameter("id");
        //2. 调用service删除
        int count = brandService.deleteById(Integer.parseInt(id));
        //3.跳转到selectAllServlet（重定向）
        response.sendRedirect("/wk12_d2_mvc_exmaple_war/selectAllServlet");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);

    }
}
